<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>宠物详情 - 宠物医院管理系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/css/style.css" rel="stylesheet">
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <!-- 侧边栏 -->
            <div class="col-md-2 p-0">
                <%@ include file="../common/admin-sidebar.jsp" %>
            </div>
            
            <!-- 主内容区域 -->
            <div class="col-md-10">
                <div class="main-content p-4">
                    <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                        <h1 class="h2">宠物详情</h1>
                        <div class="btn-toolbar mb-2 mb-md-0">
                            <div class="btn-group me-2">
                                <a href="${pageContext.request.contextPath}/pet/list" class="btn btn-sm btn-outline-secondary">
                                    <i class="fas fa-arrow-left"></i> 返回列表
                                </a>
                                <a href="${pageContext.request.contextPath}/pet/edit?id=${pet.petId}" class="btn btn-sm btn-outline-primary">
                                    <i class="fas fa-edit"></i> 编辑宠物
                                </a>
                                <button type="button" class="btn btn-sm btn-outline-danger" onclick="deletePet(${pet.petId})">
                                    <i class="fas fa-trash"></i> 删除宠物
                                </button>
                            </div>
                        </div>
                    </div>

                    <!-- 宠物详情 -->
                    <div class="row">
                        <div class="col-lg-8">
                            <!-- 基本信息 -->
                            <div class="card mb-4">
                                <div class="card-header">
                                    <h5 class="card-title mb-0">
                                        <i class="fas fa-info-circle text-primary"></i> 基本信息
                                    </h5>
                                </div>
                                <div class="card-body">
                                    <div class="row">
                                        <div class="col-md-6">
                                            <table class="table table-borderless">
                                                <tr>
                                                    <td class="fw-bold" style="width: 120px;">宠物ID：</td>
                                                    <td>${pet.petId}</td>
                                                </tr>
                                                <tr>
                                                    <td class="fw-bold">宠物姓名：</td>
                                                    <td class="text-primary fw-bold">${pet.petName}</td>
                                                </tr>
                                                <tr>
                                                    <td class="fw-bold">宠物类型：</td>
                                                    <td>${pet.petType}</td>
                                                </tr>
                                                <tr>
                                                    <td class="fw-bold">品种：</td>
                                                    <td>${pet.breed}</td>
                                                </tr>
                                                <tr>
                                                    <td class="fw-bold">性别：</td>
                                                    <td>
                                                        <c:choose>
                                                            <c:when test="${pet.gender == 'male'}">
                                                                <i class="fas fa-mars text-primary"></i> 雄性
                                                            </c:when>
                                                            <c:when test="${pet.gender == 'female'}">
                                                                <i class="fas fa-venus text-danger"></i> 雌性
                                                            </c:when>
                                                            <c:otherwise>未知</c:otherwise>
                                                        </c:choose>
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                        <div class="col-md-6">
                                            <table class="table table-borderless">
                                                <tr>
                                                    <td class="fw-bold" style="width: 120px;">年龄：</td>
                                                    <td>
                                                        <c:choose>
                                                            <c:when test="${not empty pet.age}">
                                                                ${pet.age}个月
                                                            </c:when>
                                                            <c:otherwise>
                                                                <span class="text-muted">未填写</span>
                                                            </c:otherwise>
                                                        </c:choose>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="fw-bold">体重：</td>
                                                    <td>
                                                        <c:choose>
                                                            <c:when test="${not empty pet.weight}">
                                                                ${pet.weight}kg
                                                            </c:when>
                                                            <c:otherwise>
                                                                <span class="text-muted">未填写</span>
                                                            </c:otherwise>
                                                        </c:choose>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="fw-bold">毛色：</td>
                                                    <td>
                                                        <c:choose>
                                                            <c:when test="${not empty pet.color}">
                                                                ${pet.color}
                                                            </c:when>
                                                            <c:otherwise>
                                                                <span class="text-muted">未填写</span>
                                                            </c:otherwise>
                                                        </c:choose>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="fw-bold">健康状态：</td>
                                                    <td>
                                                        <c:choose>
                                                            <c:when test="${pet.status == 'healthy'}">
                                                                <span class="badge bg-success">健康</span>
                                                            </c:when>
                                                            <c:when test="${pet.status == 'sick'}">
                                                                <span class="badge bg-warning">生病</span>
                                                            </c:when>
                                                            <c:when test="${pet.status == 'injured'}">
                                                                <span class="badge bg-danger">受伤</span>
                                                            </c:when>
                                                            <c:otherwise>
                                                                <span class="badge bg-secondary">未知</span>
                                                            </c:otherwise>
                                                        </c:choose>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="fw-bold">注册时间：</td>
                                                    <td>
                                                        <fmt:formatDate value="${pet.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <!-- 主人信息 -->
                            <c:if test="${not empty pet.owner}">
                                <div class="card mb-4">
                                    <div class="card-header">
                                        <h5 class="card-title mb-0">
                                            <i class="fas fa-user text-info"></i> 主人信息
                                        </h5>
                                    </div>
                                    <div class="card-body">
                                        <div class="row">
                                            <div class="col-md-6">
                                                <table class="table table-borderless">
                                                    <tr>
                                                        <td class="fw-bold" style="width: 120px;">姓名：</td>
                                                        <td>${pet.owner.realName}</td>
                                                    </tr>
                                                    <tr>
                                                        <td class="fw-bold">用户名：</td>
                                                        <td>${pet.owner.username}</td>
                                                    </tr>
                                                </table>
                                            </div>
                                            <div class="col-md-6">
                                                <table class="table table-borderless">
                                                    <tr>
                                                        <td class="fw-bold" style="width: 120px;">手机号：</td>
                                                        <td>
                                                            <c:choose>
                                                                <c:when test="${not empty pet.owner.phone}">
                                                                    ${pet.owner.phone}
                                                                </c:when>
                                                                <c:otherwise>
                                                                    <span class="text-muted">未填写</span>
                                                                </c:otherwise>
                                                            </c:choose>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td class="fw-bold">邮箱：</td>
                                                        <td>
                                                            <c:choose>
                                                                <c:when test="${not empty pet.owner.email}">
                                                                    ${pet.owner.email}
                                                                </c:when>
                                                                <c:otherwise>
                                                                    <span class="text-muted">未填写</span>
                                                                </c:otherwise>
                                                            </c:choose>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </c:if>

                            <!-- 描述信息 -->
                            <c:if test="${not empty pet.description}">
                                <div class="card mb-4">
                                    <div class="card-header">
                                        <h5 class="card-title mb-0">
                                            <i class="fas fa-sticky-note text-secondary"></i> 描述信息
                                        </h5>
                                    </div>
                                    <div class="card-body">
                                        <p class="mb-0" style="white-space: pre-wrap;">${pet.description}</p>
                                    </div>
                                </div>
                            </c:if>
                        </div>

                        <!-- 侧边栏信息 -->
                        <div class="col-lg-4">
                            <!-- 宠物照片 -->
                            <div class="card mb-4">
                                <div class="card-header">
                                    <h5 class="card-title mb-0">
                                        <i class="fas fa-camera text-primary"></i> 宠物照片
                                    </h5>
                                </div>
                                <div class="card-body text-center">
                                    <c:choose>
                                        <c:when test="${not empty pet.photoUrl}">
                                            <img src="${pageContext.request.contextPath}/${pet.photoUrl}" 
                                                 alt="${pet.petName}" class="img-fluid rounded shadow" 
                                                 style="max-width: 100%; max-height: 300px; object-fit: cover;">
                                        </c:when>
                                        <c:otherwise>
                                            <div class="bg-light rounded d-flex align-items-center justify-content-center" 
                                                 style="height: 200px;">
                                                <div class="text-center">
                                                    <i class="fas fa-paw fa-4x text-muted mb-3"></i>
                                                    <p class="text-muted">暂无照片</p>
                                                </div>
                                            </div>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>

                            <!-- 操作按钮 -->
                            <div class="card">
                                <div class="card-header">
                                    <h5 class="card-title mb-0">
                                        <i class="fas fa-cogs text-secondary"></i> 操作
                                    </h5>
                                </div>
                                <div class="card-body">
                                    <div class="d-grid gap-2">
                                        <a href="${pageContext.request.contextPath}/pet/edit?id=${pet.petId}" 
                                           class="btn btn-primary">
                                            <i class="fas fa-edit"></i> 编辑宠物信息
                                        </a>
                                        <a href="${pageContext.request.contextPath}/health/list?petId=${pet.petId}" 
                                           class="btn btn-success">
                                            <i class="fas fa-heartbeat"></i> 查看健康记录
                                        </a>
                                        <a href="${pageContext.request.contextPath}/appointment/list?petId=${pet.petId}" 
                                           class="btn btn-info">
                                            <i class="fas fa-calendar-check"></i> 查看预约记录
                                        </a>
                                        <button type="button" class="btn btn-danger" onclick="deletePet(${pet.petId})">
                                            <i class="fas fa-trash"></i> 删除宠物
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // 删除宠物
        function deletePet(petId) {
            if (confirm('确定要删除这只宠物吗？此操作不可恢复！\n删除宠物将同时删除相关的健康记录和预约记录。')) {
                window.location.href = '${pageContext.request.contextPath}/pet/delete?id=' + petId;
            }
        }
    </script>
</body>
</html>
